<template>
  <el-dialog :title="`${formtype=='1'?'添加':'修改'}自由裁量权`" :visible.sync="dialogVisible" @opened="dialogOpen">
    <el-form ref="form" :model="form" label-width="80px" size="small">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item  label="违法行为" prop="caseCauseName">
            <el-select v-model="form.caseCauseName" placeholder="请选择" style="width: 100%">
              <el-option
                      v-for="item in postList"
                      :key="item.casecauseId"
                      :label="item.content"
                      :value="item.casecauseId"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="wfcd" label="违法程度">
            <el-select v-model="form.wfcd" placeholder="请选择" style="width: 100%">
              <el-option
                      v-for="item in lawtypeList"
                      :key="item.id"
                      :label="item.wfcd"
                      :value="item.wfcd"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item prop="wfqj" label="违法情节">
            <el-input v-model="form.wfqj"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="cfbz" label="处罚标准">
            <el-input v-model="form.cfbz"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item prop="lawerLimit" label="罚款下限">
            <el-input v-model="form.lawerLimit"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="upperLimit" label="罚款上限">
            <el-input v-model="form.upperLimit"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item class="from-bnts">
        <el-button type="primary" @click="submit">保存</el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
  import userApi from "@/api/system/user";
  import deptApi from "@/api/system/dept";
  import roleApi from "@/api/system/role";
  import discretionApi from "@/api/system/discretion";
  import utils from '@/assets/utils/zhzf-util';
  import dictCache from "@/assets/utils/cache-dict-util";
  export default {
    name: "userEditForm",
    props: {
      value: Boolean
    },
    data() {
      return {
        loading: false,
        dialogVisible: false,
        form: {},
        postList: [],
        formtype:'',
        lawtypeList: [{
          id: '1',
          wfcd: '轻微'
        }, {
          id: '2',
          wfcd: '一般'
        }, {
          id: '3',
          wfcd: '较重'
        }, {
          id: '4',
          wfcd: '严重'
        }, {
          id: '5',
          wfcd: '特别严重'
        }],
      };
    },

    watch: {
      value(val) {
        this.dialogVisible = val;
      },
      dialogVisible(val) {
        this.$emit("input", val);
      }
    },
    methods: {
      async getdepData(param) {
        this.postList = param.breakdroplist;
        this.formtype = param.handletype;
        this.dialogVisible = true;
        this.form = param.info||{};
        this.$forceUpdate();
      },
      async dialogOpen(){
      },
      submit() {
        this.$refs["form"].validate(async valid => {
          if (!valid) {
            return false;
          }
          this.loading = true;
          await this.saveDiscretionInfo();
          this.loading = false;
          this.dialogVisible = false;
          this.$emit("submit");
        });
      },
       getcaseContent(){
        let lawlist = this.postList;
        if(this.form.caseCauseName){
          for(var i=0;i<lawlist.length;i++){
            if(this.form.caseCauseName==lawlist[i].casecauseId){
                this.form.caseCauseId = this.form.caseCauseName;
                this.form.caseCauseName= lawlist[i].content;
            }
          }
        }
      },
      async saveDiscretionInfo() {
        let time = new Date();
        this.form.createdDatetime = time.getTime();
        this.form.enabled = '0';
        this.form.emailValidated = '0';
        this.form.mobilePhoneValidated = '0';
        this.getcaseContent();
        let method = this.formtype=='1' ? discretionApi.add : discretionApi.mod;
        let res = await method({...this.form});
        if(res.ok){
          utils.showTips("ok");
        }
      },
      close() {
        this.$refs["form"].resetFields();
        this.dialogVisible = false;
      }
    }
  };
</script>
<style scss>
  .el-dialog{
    width: 50% !important;
  }

</style>

